                PRESERVE8
                THUMB
                AREA |.text|, CODE, READONLY
                    
;***** StartCritical *****
; make a copy of previous I bit, disable interrupts
; inputs  : none
; outputs : previous bit
                EXPORT  StartCritical
StartCritical
                MRS     R0, PRIMASK
                CPSID   I
                BX      LR
                
                ALIGN

;***** EndCritical *****
; use the copy of previous I bit, restore I bit to previous value
; inputs  : previous bit
; outputs : none
                EXPORT  EndCritical
EndCritical
                MSR     PRIMASK, R0
                BX      LR
                
                ALIGN
                    
                END
                    